Processing microtome slides with GIMP and ImageJ

Roman M. Link

Introduction

This is a simplified short form of the BOT2 tutorial for the pre-processing and analysis of wood anatomical microtome slides based on GIMP and ImageJ which is meant for in-class use.

A list of useful GIMP shortcuts can be found here: (https://www.gimpusers.com/gimp/hotkeys).

Note that the term CODE in this document is a placeholder that has to be replaced by the unique ID of sample you are working with! In the screenshots in this example, the CODE is CRI_3_010.

Important note

All ImageJ results tables can be saved either in ‘Comma Separated Value’ (.csv) or whitespace/tabstop separated format (generated when saving with a .xls extension, but actually just a plain text format). In either case, the output is optimized for US/UK locales, which means that points are used as a decimal separator. In order to process these files on German systems without compatibility issues, it is important to make sure that the system-wide decimal separator is correctly set before starting the analysis.

In German Windows 10, the option to change the decimal separator is well hidden:

Start Menu ➜ Windows-System ➜ Systemsteuerung ➜ Zeit und Region ➜ Region ➜ Formate ➜ Weitere Einstellungen ➜ Dezimaltrennzeichen

To avoid data compatibility problems, make sure the decimal separator is set to “.”. In this case, you will want the grouping symbol (Symbol für Zifferngruppierung) to be a comma instead of the point symbol used in Germany.

If you do not want to change your system settings, you can alternatively export everything in a .csv format and use Excel’s Daten ➜ Text in Spalten menu to manually set field delimitor and decimal separator.

It is generally recommended to create a separate folder for each sample and to keep all files belonging to the sample in this folder. Folders should always be named by sample ID.

Preparation in GIMP

  1. Open original image CODE.jpg

  1. Cut out a wedge of the original image with the Polygon Lasso tool (GIMP shortcut: F)

  1. Save the file CODE_GI_cropped_01.jpg (using the “Export as” option or via Ctrl + Shift + E).

  2. Close tab with original image (do not save changes!)

  3. [optionally] adjust brightness and contrast using color curves (German: Farben ➜ Kurven, English: Colors ➜ Curves)

  1. If your sample is surrounded by transparency (indicated by a checkerboard pattern) instead of a white background:
  2. Decompose the image into its RGB components (German: Farben ➜ Komponenten ➜ Zerlegen, English: Colors ➜ Components ➜ Decompose) - this creates a new image that separates the original image into its red, green and blue channel (if this step changes the shape of the wood section and suddenly cut-out areas reappear, you forgot to delete the alpha channel).

  1. Hide all layers except the green layer by clicking on the eye symbol in the Layers panel, then export (Ctrl + Shift + E) the new image as CODE_GI_cropped_02.jpg.

  1. Close the tab with the black and white image.

Analysis in ImageJ

  1. open ImageJ.

  1. open the original image with the scale bar (CODE.jpg) with ImageJ (either by the File dialog or by dragging and dropping onto the ImageJ window).
  2. zoom in (Strg + mouse wheel) and move the image with the hand tool (or by holding & clicking while pressing the space bar) until the scale bar fills the entire screen.
  3. use the Straight Line tool to draw a line from one end of the scale bar to the other.

  1. Set the scale to the appropriate value by going to the Analyze ➜ Set Scale menu.

  1. In the corresponding dialog, set the Known Distance (the value above the scale bar), the Unit of length (normally µm; see scale bar) and - very important - mark the box Global to make sure that the scale is the same accross all opened documents.

  1. Open the modified image CODE_GI_cropped_02.jpg with ImageJ (drag & drop onto ImageJ bar) - if the scale is correctly set, the dimensions of the picture in µm should be visible in the upper left corner (if the values is in pixels).
  2. Transform the grayscale image into a threshold image

  1. Save this image as CODE_GI_cropped_02_TH_01.jpg

  1. zoom out and measure the area of the sample

  1. open the saving dialog by clicking File ➜ Save As in the Results window and save as CODE_GI_cropped_02_TH_01_Area.xls. The area of the analyzed wood portion can then be calculated by substracting the black area from the total area of the image.

  1. Use the Flood Fill tool to replace the surrounding black area with a solid white color.

  1. Save the image without the black area as CODE_GI_cropped_02_TH_02.jpg

  2. To prepare for automated vessel detection, open the Analyze ➜ Set Measurements dialog and select Area, Shape descriptors, Perimeter, Fit ellipse and Feret’s diameter

  1. Open the Analyze ➜ Analyze Particles dialog,
  1. before clicking OK, make sure to select Show: Outlines, and mark Display Results, Clear Results and Include Holes.

  1. Save the resulting outlines as a .jpg document, specifying the selected Area and Circularity values in the name (e.g. CODE_GI_cropped_02_TH_02_Outlines_300,0.3.jpg) using the File ➜ Save As ➜ Jpeg option in the main menu of ImageJ (not the newly opened Results window!). Make sure the right image window is selected when saving.

  1. Do not close ImageJ, or you will have to set the scale again!

Error inspection in GIMP

the simplified workflow in the next couple of screenshots was documented on a computer running Ubuntu Mate and a different version of GIMP, but should work just the same on Windows

  1. Open the threshold file (CODE_GI_cropped_02_TH_02.jpg) and the outline file(CODE_GI_cropped_02_TH_02_Outlines_300,0.3.jpg) in GIMP (mark both files, right click and select Open with GIMP / Öffnen mit GIMP).
  2. Go to the tab with the outline file, mark everything (STRG + A), copy (STRG + C), select the tab with the threshold image and paste the outlines on top of the threshold image (STRG + V).

  1. Right click on the layer in the layer menu (usually bottom right, should be displayed as a “floating selection”/“schwebende Auswahl” by now) and select **To new Layer ** / Zur neuen Ebene.

  1. Choose the Wand tool (click in image area and press U) and click into the white area surrounding the outlines.

  1. Cut out the white background with STRG + X.
  2. Now the threshold image and the classification are overlaid, and it should be possible to identify places where the classification did not work.
  3. Most common problems:

  1. If there is a large number of misclassifications, go back to ImageJ and repeat the Analyze Particles step with different settings for Roundness and Size.
  2. If there are only a few misclassified vessels: manually correct misclassifications of large vessels.
  3. Make sure you choose to edit the layer with the threshold image.
  4. Choose the pencil tool (shortcut: N) to edit the threshold image and

  1. Zoom in to places where large vessels were misclassified and “repair” large vessels with wall damage that reduces their roundness below the classification level.

  1. Use white color to remove tracheids that are erroneously classified as vessels,

  1. When you have finished editing, hide the outline layer (eye symbol!) and export the threshold layer as CODE_GI_cropped_02_TH_02_edit.jpg using the “Export as” dialog or Strg + Shift + E.

Final steps

  1. Now, open the image in ImageJ (drag and drop) [if no size in µm is shown on the upper left of the image window, you have to set the scale again; see above],
  2. Click on Image ➜ Type ➜ 8bit to make sure resetting the threshold works,
  3. Reset the threshold by clicking Image ➜ Adjust ➜ Threshold

  1. Repeat all steps starting from the Analyze Particles section.

  2. Save the new outlines as CODE_GI_cropped_02_TH_02_edit_Outlines_300,0.3.jpg (File ➜ Save As in the main window).

  3. If you are happy with your classification results, save them as CODE_GI_cropped_02_TH_02_edit_Outlines_300,0.3_Results.xls (File ➜ Save as in the Results window).

  4. Use GIMP to copy the new outlines on top of the threshold image and cut out the background (just as in this step).

  5. Save the resulting image (using the “Export as” dialog or _STRG + Shift + E__) using the name CODE_GI_cropped_02_TH_02_edit_Outlines_300,0.3_Analysis.jpg.

  6. Your project folder should now look somewhat like this (note that often, you will have to try more than one setting for circularity and minimum vessels size, and you will have to do more than one edit, which all show up as additional files in the project folder):